{include file='Public/header' /}
<div class="layui-layout layui-layout-admin">
{include file='Public/head' /}	
{include file='Public/side' /}
<div class="layui-body"> 
{include file='Public/crumbs' /}
	<!-- 内容主体区域 -->
	<div class="shu-body">
		<div class="layui-fluid">
			<div class="layui-row layui-col-space15">
				<div class="layui-col-md12 layui-col-xs12">
					<form class="layui-form" method="post">
						<a href="{:url('add')}" class="layui-btn"><i class="layui-icon">&#xe61f;</i> 添加</a>
						<table lay-even class="layui-table">
							<colgroup>
							<col width="50">
							</colgroup>
							<thead>
								<tr>
									<th> 
									<input type="checkbox" name="checkAll" lay-filter="checkAll">
										<div class="layui-unselect layui-form-checkbox" lay-skin=""> <i class="layui-icon">&#xe618;</i> </div>
									</th>
									<th>菜单名称</th>
									<th>链接</th>
									<th>传参值</th>
									<th>ICON</th>
									<th class="center">状态</th>
									<th>排序</th>
									<th class="center">操作</th>
								</tr>
							</thead>
							<tbody>
							
							{volist name="list" id="val"}
							<tr>
								<td align="center"> {empty name="val.children"}
									<input type="checkbox" name="ids[{$val['id']}]" lay-filter="checkOne" value="{$val['id']}">
									<div class="layui-unselect layui-form-checkbox" lay-skin=""><i class="layui-icon">&#xe618;</i></div>
									{/empty}
									{notempty name="val.children"}--{/notempty} </td>
								<td><div style="position:relative; overflow:hidden;">{$val['title']}<span class="dian" data-id="{$val['id']}" data-type="1" style="cursor:pointer; position:absolute; width:100%; left:0px; text-align:right;">+</span></div></td>
								<td>{$val['name']}</td>
								<td>{$val['cs']}</td>
								<td><i class="{$val.icon}"></i></td>
								<td class="center">
								{if condition="$val['islink'] eq 1 "} 
								<input type="checkbox" checked name="switch" lay-skin="switch" lay-text="显示|隐藏" lay-filter="switchTest" value="1" val='{:url('islink',array('id'=>$val['id']))}'> 
								{else /} 
								<input type="checkbox" name="switch" lay-skin="switch" lay-text="显示|隐藏" lay-filter="switchTest" value="1" val='{:url('islink',array('id'=>$val['id']))}'>
								{/if} 
								</td>
								<td>{$val['o']}</td>
								<td>
								<a class="layui-btn layui-btn-sm" href="{:url('edit',array('id'=>$val['id']))}">修改</a>
								{empty name="val.children"}
								<a class="layui-btn layui-btn-sm layui-btn-danger del_btn"  href="javascript:;" title="没有子栏目可直接删除" nickname="{$val['title']}" val="{:url('del',array('ids'=>$val['id']))}">删除</a> 
								{/empty} 
								</td>
							</tr>
							{notempty name="val.children"}
							{volist name="val.children" id="v"}
							<tr class="toto{$val['id']} navnone">
								<td><input type="checkbox" name="ids[{$v['id']}]" lay-filter="checkOne" value="{$v['id']}"></td>
								<td>┗━{$v['title']}</td>
								<td>{$v['name']}</td>
								<td>{$v['cs']}</td>
								<td><i class="{$v.icon}"></i></td>
								<td class="center"> 
								{if condition="$v['islink'] eq 1 "} 
								<input type="checkbox" checked name="switch" lay-skin="switch" lay-text="显示|隐藏" lay-filter="switchTest" value="1" val='{:url('islink',array('id'=>$v['id']))}'> 
								{else /} 
								<input type="checkbox" name="switch" lay-skin="switch" lay-text="显示|隐藏" lay-filter="switchTest" value="1" val='{:url('islink',array('id'=>$v['id']))}'>
								{/if} 
								</td>
								<td>{$v['o']}</td>
								<td>
								<a class="layui-btn layui-btn-sm" href="{:url('edit',array('id'=>$v['id']))}">修改</a><a class="layui-btn layui-btn-sm layui-btn-danger del_btn" href="javascript:;" title="没有子栏目可直接删除" nickname="{$v['title']}" val="{:url('del',array('ids'=>$v['id']))}">删除</a> 
								
								</td>
							</tr>
							{notempty name="v.children"}
							{volist name="v.children" id="vv"}
							<tr class="tototo{$val['id']} navnone">
								<td><input type="checkbox" name="ids[{$vv['id']}]" lay-filter="checkOne" value="{$vv['id']}"></td>
								<td>&nbsp;&nbsp;&nbsp;&nbsp;┗━{$vv['title']}</td>
								<td>{$vv['name']}</td>
								<td>{$vv['cs']}</td>
								<td><i class="{$vv.icon}"></i></td>
								<td class="center"> 
								{if condition="$vv['islink'] eq 1 "} 
								<input type="checkbox" checked name="switch" lay-skin="switch" lay-text="显示|隐藏" lay-filter="switchTest" value="1" val='{:url('islink',array('id'=>$vv['id']))}'>
								{else /}
								<input type="checkbox" name="switch" lay-skin="switch" lay-text="显示|隐藏" lay-filter="switchTest" value="1" val='{:url('islink',array('id'=>$vv['id']))}'> 
								{/if}
								</td>
								<td>{$vv['o']}</td>
								<td>
								<a class="layui-btn layui-btn-sm" href="{:url('edit',array('id'=>$vv['id']))}">修改</a><a class="layui-btn layui-btn-sm layui-btn-danger del_btn" href="javascript:;" title="没有子栏目可直接删除" nickname="{$vv['title']}" val="{:url('del',array('ids'=>$vv['id']))}">删除</a> 
							
								</td>
							</tr>
							{/volist}
							{/notempty}
							{/volist}
							{/notempty}	 
							{/volist}
								</tbody>
							
						</table>
						<a class="layui-btn" lay-submit lay-filter="delete"><i class="layui-icon">&#xe640;</i> 批量删除</a>
					</form>
				</div>
			</div>
		</div>
	</div>
	<!-- 内容主体区域 END--> 
</div>
{include file='Public/footer' /} 
<script>
layui.use('form',function(){
  var form = layui.form,
  jq = layui.jquery;

  form.on('checkbox(checkAll)', function(data){
    if(data.elem.checked){
      jq("input[lay-filter='checkOne']").prop('checked',true);
    }else{
      jq("input[lay-filter='checkOne']").prop('checked',false);
    }
    form.render('checkbox');
  });  

  form.on('checkbox(checkOne)', function(data){
    var is_check = true;
    if(data.elem.checked){
      jq("input[lay-filter='checkOne']").each(function(){
        if(!jq(this).prop('checked')){ is_check = false; }
      });
      if(is_check){
        jq("input[lay-filter='checkAll']").prop('checked',true);
      }
    }else{
      jq("input[lay-filter='checkAll']").prop('checked',false);
    } 
    form.render('checkbox');
  });
  
  jq('.del_btn').click(function(){
	var name = jq(this).attr('nickname');
    var url = jq(this).attr('val');
    layer.confirm('确定删除【'+name+'】栏目?', function(index){
      loading = layer.load(2, {
        shade: [0.2,'#000']
      });
      jq.get(url,function(data){
        if(data.code == 200){
          layer.close(loading);
          layer.msg(data.msg, {icon: 1, time: 1000}, function(){
            location.reload();
          });
        }else if(data.code == 0){
          layer.close(loading);
          layer.msg(data.msg, {icon: 2, anim: 6, time: 1000});
        }
      });
    });   
  });

  form.on('submit(delete)', function(data){
    var is_check = false;
    jq("input[lay-filter='checkOne']").each(function(){
      if(jq(this).prop('checked')){ is_check = true; }
    });
    if(!is_check){
      layer.msg('请选择数据', {icon: 2,anim: 6,time: 1000});
      return false;
    }
    layer.confirm('确定批量删除?', function(index){
      loading = layer.load(2, {
        shade: [0.2,'#000']
      });
      var param = data.field;
      jq.post("{:url('del')}",param,function(data){
        if(data.code == 200){
          layer.close(loading);
          layer.msg(data.msg, {icon: 1, time: 1000}, function(){
            location.reload();
          });
        }else if(data.code == 0){
          layer.close(loading);
          layer.msg(data.msg, {icon: 2,anim: 6, time: 1000});
        }
      });
    });
	
    return false;
  });
  
  //监听指定开关 
  form.on('switch(switchTest)', function(data){
	  var url = jq(this).attr('val');
	  loading = layer.load(2, {
		shade: [0.2,'#000']
	  });
      jq.get(url,function(data){
        if(data.code == 200){
          layer.close(loading);
          layer.msg(data.msg, {icon: 1, time: 1000}, function(){
            //location.reload();
          });
        }else if(data.code == 0){
          layer.close(loading);
          layer.msg(data.msg, {icon: 2, anim: 6, time: 1000});
        }
      });
  });
  
  	//打开关闭子菜单
	jq('.navnone').hide();
	jq('.dian').click(function(){
		var othis=jq(this),id=jq(this).attr('data-id'),type=jq(this).attr('data-type');
		if(type==1){
			jq('.toto'+id).show();
			jq('.tototo'+id).show();
			jq(this).text('-');
			jq(this).attr('data-type',0);
		}else{
			jq('.toto'+id).hide();
			jq('.tototo'+id).hide();
			jq(this).text('+');
			jq(this).attr('data-type',1);
		}
	})
})
</script> 
